package com.example.mybatis.datasource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class MyRoutingDataSourceHolder implements RoutingDataSourceHolder{

    private final MyRoutingDataSource myRoutingDataSource;

    @Autowired
    public MyRoutingDataSourceHolder(MyRoutingDataSource myRoutingDataSource) {
        this.myRoutingDataSource = myRoutingDataSource;
    }

    @Override
    public Object showCurrentLookupKey() {
        return myRoutingDataSource.determineCurrentLookupKey();
    }

    @Override
    public void determineCurrentDataSource(String lookupKey) {
        myRoutingDataSource.setLookupKey(lookupKey);
    }

    @Override
    public void reset() {
        myRoutingDataSource.reset();
    }

    @Override
    public Set<String> showAllLookupKeys() {
        return myRoutingDataSource.getMyLookupKeys();
    }
}
